﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VCN.App.DataAccessLayer;

namespace VCN
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        public string[] m_str_admin;
        protected void Page_Load(object sender, EventArgs e)
        {
            m_str_admin = new string[10];
            UsersDAO v_userDAO = new UsersDAO();
            DataTable v_dt_adminName = v_userDAO.GetAdminName();
            // Lấy tất cả UserName có quyền Admin và cho vào một array
            for (int i = 0; i < v_dt_adminName.Rows.Count; i++)
            {
                m_str_admin[i] = v_dt_adminName.Rows[i]["Username"].ToString();
            }

            //Gán link cho sửa tin công ty
            Get_ID_News_Company();
            Get_ID_News_Product();
        }

        public void Get_ID_News_Company()
        {
            VCN.App.DataAccessLayer.NewsDAO v_dao_news = new VCN.App.DataAccessLayer.NewsDAO();
            VCN.App.DataTransferObjects.News v_news_obj = v_dao_news.selectCompanyNews();
            if (v_news_obj != null)
                m_hpl_cogty.NavigateUrl = "/admin/NewsManagement.aspx?Id="+ v_news_obj.Id.ToString();  
            else
                m_hpl_cogty.NavigateUrl = "/admin/default.aspx";
        }

        public void Get_ID_News_Product()
        {
            VCN.App.DataAccessLayer.NewsDAO newDao = new VCN.App.DataAccessLayer.NewsDAO();
            VCN.App.DataTransferObjects.News v_new = newDao.selectNewsProduct();
            if (v_new != null)
                m_hpl_sanpham.NavigateUrl = "/admin/NewsManagement.aspx?Id=" + v_new.Id.ToString();
            else
                m_hpl_sanpham.NavigateUrl = "/admin/default.aspx";
        }
    }
}
